package Classes.GameUtils
{
	import flash.display.DisplayObject;
	import flash.system.ApplicationDomain;
	import flash.utils.getDefinitionByName;
	import flash.utils.getQualifiedClassName;
	
	/**
	 *  样式管理 
	 *   提供样式管理 以及样式构造等方法 
	 *  @author tyh
	 */	
	public class StyleManager
	{
		/** 样式单例 **/		
		private static var _instance:StyleManager;
		
		private var _uiDomain:ApplicationDomain;
		
		
		public function StyleManager()
		{
			
		}
		
		/**
		 * 获得样式管理单例
		 * @return 
		 */		
		public static function getInstance():StyleManager{
			if(_instance == null){ _instance = new StyleManager(); }
			return _instance;
		}
		
		/**
		 * 根据类名返回类对象 
		 * @param component
		 * @return 
		 */		
		public function getClassDef(component:Object):Class {
			if (component is Class) { 
				return (component as Class);
			}
			try {
				return uiDomain.getDefinition(component.toString()) as Class;
			} catch (e:Error) {
				if (component is DisplayObject) {
					try {
						return component.loaderInfo.applicationDomain.getDefinition(getQualifiedClassName(component)) as Class;
					} catch (e:Error) {}
				}
			}
			return null;
		}
		

		public function get uiDomain():ApplicationDomain
		{
			return ApplicationDomain.currentDomain;
		}

		public function set uiDomain(value:ApplicationDomain):void
		{
			_uiDomain = value;
		}

	}
}